home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / mallcrawl.swf / scripts / __Packages / mx / controls / SimpleButton.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  14.4 KB  |  559 lines

  1. class mx.controls.SimpleButton extends mx.core.UIComponent
  2. {
  3.    var preset;
  4.    var boundingBox_mc;
  5.    var skinName;
  6.    var linkLength;
  7.    var iconName;
  8.    var __width;
  9.    var __height;
  10.    var __emphaticStyleName;
  11.    var styleName;
  12.    var dispatchEvent;
  13.    var autoRepeat;
  14.    var interval;
  15.    static var emphasizedStyleDeclaration;
  16.    static var symbolName = "SimpleButton";
  17.    static var symbolOwner = mx.controls.SimpleButton;
  18.    static var version = "2.0.2.126";
  19.    var className = "SimpleButton";
  20.    var style3dInset = 4;
  21.    var btnOffset = 1;
  22.    var __toggle = false;
  23.    var __state = false;
  24.    var __emphasized = false;
  25.    var __emphatic = false;
  26.    static var falseUp = 0;
  27.    static var falseDown = 1;
  28.    static var falseOver = 2;
  29.    static var falseDisabled = 3;
  30.    static var trueUp = 4;
  31.    static var trueDown = 5;
  32.    static var trueOver = 6;
  33.    static var trueDisabled = 7;
  34.    var falseUpSkin = "SimpleButtonUp";
  35.    var falseDownSkin = "SimpleButtonIn";
  36.    var falseOverSkin = "";
  37.    var falseDisabledSkin = "SimpleButtonUp";
  38.    var trueUpSkin = "SimpleButtonIn";
  39.    var trueDownSkin = "";
  40.    var trueOverSkin = "";
  41.    var trueDisabledSkin = "SimpleButtonIn";
  42.    var falseUpIcon = "";
  43.    var falseDownIcon = "";
  44.    var falseOverIcon = "";
  45.    var falseDisabledIcon = "";
  46.    var trueUpIcon = "";
  47.    var trueDownIcon = "";
  48.    var trueOverIcon = "";
  49.    var trueDisabledIcon = "";
  50.    var phase = "up";
  51.    var fui = "falseUpIcon";
  52.    var fus = "falseUpSkin";
  53.    var fdi = "falseDownIcon";
  54.    var fds = "falseDownSkin";
  55.    var frs = "falseOverSkin";
  56.    var fri = "falseOverIcon";
  57.    var dfi = "falseDisabledIcon";
  58.    var dfs = "falseDisabledSkin";
  59.    var tui = "trueUpIcon";
  60.    var tus = "trueUpSkin";
  61.    var tdi = "trueDownIcon";
  62.    var tds = "trueDownSkin";
  63.    var trs = "trueOverSkin";
  64.    var tri = "trueOverIcon";
  65.    var dts = "trueDisabledSkin";
  66.    var dti = "trueDisabledIcon";
  67.    var rolloverSkin = mx.controls.SimpleButton.prototype.frs;
  68.    var rolloverIcon = mx.controls.SimpleButton.prototype.fri;
  69.    var upSkin = mx.controls.SimpleButton.prototype.fus;
  70.    var downSkin = mx.controls.SimpleButton.prototype.fds;
  71.    var disabledSkin = mx.controls.SimpleButton.prototype.dfs;
  72.    var upIcon = mx.controls.SimpleButton.prototype.fui;
  73.    var downIcon = mx.controls.SimpleButton.prototype.fdi;
  74.    var disabledIcon = mx.controls.SimpleButton.prototype.dfi;
  75.    var initializing = true;
  76.    var idNames = ["fus","fds","frs","dfs","tus","tds","trs","dts","fui","fdi","fri","dfi","tui","tdi","tri","dti"];
  77.    var stateNames = ["falseUp","falseDown","falseOver","falseDisabled","trueUp","trueDown","trueOver","trueDisabled"];
  78.    var refNames = ["upSkin","downSkin","rolloverSkin","disabledSkin"];
  79.    var tagMap = {falseUpSkin:0,falseDownSkin:1,falseOverSkin:2,falseDisabledSkin:3,trueUpSkin:4,trueDownSkin:5,trueOverSkin:6,trueDisabledSkin:7,falseUpIcon:0,falseDownIcon:1,falseOverIcon:2,falseDisabledIcon:3,trueUpIcon:4,trueDownIcon:5,trueOverIcon:6,trueDisabledIcon:7};
  80.    function SimpleButton()
  81.    {
  82.       super();
  83.    }
  84.    function init(Void)
  85.    {
  86.       super.init();
  87.       if(this.preset == undefined)
  88.       {
  89.          this.boundingBox_mc._visible = false;
  90.          this.boundingBox_mc._width = this.boundingBox_mc._height = 0;
  91.       }
  92.       this.useHandCursor = false;
  93.    }
  94.    function createChildren(Void)
  95.    {
  96.       if(this.preset != undefined)
  97.       {
  98.          var _loc2_ = this[this.idNames[this.preset]];
  99.          this[this.refNames[this.preset]] = _loc2_;
  100.          this.skinName = _loc2_;
  101.          if(this.falseOverSkin.length == 0)
  102.          {
  103.             this.rolloverSkin = this.fus;
  104.          }
  105.          if(this.falseOverIcon.length == 0)
  106.          {
  107.             this.rolloverIcon = this.fui;
  108.          }
  109.          this.initializing = false;
  110.       }
  111.       else if(this.__state == true)
  112.       {
  113.          this.setStateVar(true);
  114.       }
  115.       else
  116.       {
  117.          if(this.falseOverSkin.length == 0)
  118.          {
  119.             this.rolloverSkin = this.fus;
  120.          }
  121.          if(this.falseOverIcon.length == 0)
  122.          {
  123.             this.rolloverIcon = this.fui;
  124.          }
  125.       }
  126.    }
  127.    function setIcon(tag, linkageName)
  128.    {
  129.       return this.setSkin(tag + 8,linkageName);
  130.    }
  131.    function changeIcon(tag, linkageName)
  132.    {
  133.       this.linkLength = linkageName.length;
  134.       var _loc2_ = this.stateNames[tag] + "Icon";
  135.       this[_loc2_] = linkageName;
  136.       this[this.idNames[tag + 8]] = _loc2_;
  137.       this.setStateVar(this.getState());
  138.    }
  139.    function changeSkin(tag, linkageName)
  140.    {
  141.       var _loc2_ = this.stateNames[tag] + "Skin";
  142.       this[_loc2_] = linkageName;
  143.       this[this.idNames[tag]] = _loc2_;
  144.       this.setStateVar(this.getState());
  145.    }
  146.    function viewIcon(varName)
  147.    {
  148.       var _loc4_ = varName + "Icon";
  149.       var _loc3_ = this[_loc4_];
  150.       if(typeof _loc3_ == "string")
  151.       {
  152.          var _loc5_ = _loc3_;
  153.          if(this.__emphasized)
  154.          {
  155.             if(this[_loc3_ + "Emphasized"].length > 0)
  156.             {
  157.                _loc3_ += "Emphasized";
  158.             }
  159.          }
  160.          if(this[_loc3_].length == 0)
  161.          {
  162.             return undefined;
  163.          }
  164.          _loc3_ = this.setIcon(this.tagMap[_loc5_],this[_loc3_]);
  165.          if(_loc3_ == undefined && _global.isLivePreview)
  166.          {
  167.             _loc3_ = this.setIcon(0,"ButtonIcon");
  168.          }
  169.          this[_loc4_] = _loc3_;
  170.       }
  171.       this.iconName._visible = false;
  172.       this.iconName = _loc3_;
  173.       this.iconName._visible = true;
  174.    }
  175.    function removeIcons()
  176.    {
  177.       var _loc3_ = 0;
  178.       while(_loc3_ < 2)
  179.       {
  180.          var _loc2_ = 8;
  181.          while(_loc2_ < 16)
  182.          {
  183.             this.destroyObject(this.idNames[_loc2_]);
  184.             this[this.stateNames[_loc2_ - 8] + "Icon"] = "";
  185.             _loc2_ = _loc2_ + 1;
  186.          }
  187.          _loc3_ = _loc3_ + 1;
  188.       }
  189.       this.refresh();
  190.    }
  191.    function setSkin(tag, linkageName, initobj)
  192.    {
  193.       var _loc3_ = super.setSkin(tag,linkageName,initobj == undefined ? {styleName:this} : initobj);
  194.       this.calcSize(tag,_loc3_);
  195.       return _loc3_;
  196.    }
  197.    function calcSize(Void)
  198.    {
  199.       this.__width = this._width;
  200.       this.__height = this._height;
  201.    }
  202.    function viewSkin(varName, initObj)
  203.    {
  204.       var _loc3_ = varName + "Skin";
  205.       var _loc2_ = this[_loc3_];
  206.       if(typeof _loc2_ == "string")
  207.       {
  208.          var _loc4_ = _loc2_;
  209.          if(this.__emphasized)
  210.          {
  211.             if(this[_loc2_ + "Emphasized"].length > 0)
  212.             {
  213.                _loc2_ += "Emphasized";
  214.             }
  215.          }
  216.          if(this[_loc2_].length == 0)
  217.          {
  218.             return undefined;
  219.          }
  220.          _loc2_ = this.setSkin(this.tagMap[_loc4_],this[_loc2_],initObj == undefined ? {styleName:this} : initObj);
  221.          this[_loc3_] = _loc2_;
  222.       }
  223.       this.skinName._visible = false;
  224.       this.skinName = _loc2_;
  225.       this.skinName._visible = true;
  226.    }
  227.    function showEmphasized(e)
  228.    {
  229.       if(e && !this.__emphatic)
  230.       {
  231.          if(mx.controls.SimpleButton.emphasizedStyleDeclaration != undefined)
  232.          {
  233.             this.__emphaticStyleName = this.styleName;
  234.             this.styleName = mx.controls.SimpleButton.emphasizedStyleDeclaration;
  235.          }
  236.          this.__emphatic = true;
  237.       }
  238.       else
  239.       {
  240.          if(this.__emphatic)
  241.          {
  242.             this.styleName = this.__emphaticStyleName;
  243.          }
  244.          this.__emphatic = false;
  245.       }
  246.    }
  247.    function refresh(Void)
  248.    {
  249.       var _loc2_ = this.getState();
  250.       if(this.enabled == false)
  251.       {
  252.          this.viewIcon("disabled");
  253.          this.viewSkin("disabled");
  254.       }
  255.       else
  256.       {
  257.          this.viewSkin(this.phase);
  258.          this.viewIcon(this.phase);
  259.       }
  260.       this.setView(this.phase == "down");
  261.       this.iconName.enabled = this.enabled;
  262.    }
  263.    function setView(offset)
  264.    {
  265.       if(this.iconName == undefined)
  266.       {
  267.          return undefined;
  268.       }
  269.       var _loc2_ = !offset ? 0 : this.btnOffset;
  270.       this.iconName._x = (this.__width - this.iconName._width) / 2 + _loc2_;
  271.       this.iconName._y = (this.__height - this.iconName._height) / 2 + _loc2_;
  272.    }
  273.    function setStateVar(state)
  274.    {
  275.       if(state)
  276.       {
  277.          if(this.trueOverSkin.length == 0)
  278.          {
  279.             this.rolloverSkin = this.tus;
  280.          }
  281.          else
  282.          {
  283.             this.rolloverSkin = this.trs;
  284.          }
  285.          if(this.trueOverIcon.length == 0)
  286.          {
  287.             this.rolloverIcon = this.tui;
  288.          }
  289.          else
  290.          {
  291.             this.rolloverIcon = this.tri;
  292.          }
  293.          this.upSkin = this.tus;
  294.          this.downSkin = this.tds;
  295.          this.disabledSkin = this.dts;
  296.          this.upIcon = this.tui;
  297.          this.downIcon = this.tdi;
  298.          this.disabledIcon = this.dti;
  299.       }
  300.       else
  301.       {
  302.          if(this.falseOverSkin.length == 0)
  303.          {
  304.             this.rolloverSkin = this.fus;
  305.          }
  306.          else
  307.          {
  308.             this.rolloverSkin = this.frs;
  309.          }
  310.          if(this.falseOverIcon.length == 0)
  311.          {
  312.             this.rolloverIcon = this.fui;
  313.          }
  314.          else
  315.          {
  316.             this.rolloverIcon = this.fri;
  317.          }
  318.          this.upSkin = this.fus;
  319.          this.downSkin = this.fds;
  320.          this.disabledSkin = this.dfs;
  321.          this.upIcon = this.fui;
  322.          this.downIcon = this.fdi;
  323.          this.disabledIcon = this.dfi;
  324.       }
  325.       this.__state = state;
  326.    }
  327.    function setState(state)
  328.    {
  329.       if(state != this.__state)
  330.       {
  331.          this.setStateVar(state);
  332.          this.invalidate();
  333.       }
  334.    }
  335.    function size(Void)
  336.    {
  337.       this.refresh();
  338.    }
  339.    function draw(Void)
  340.    {
  341.       if(this.initializing)
  342.       {
  343.          this.initializing = false;
  344.          this.skinName.visible = true;
  345.          this.iconName.visible = true;
  346.       }
  347.       this.size();
  348.    }
  349.    function getState(Void)
  350.    {
  351.       return this.__state;
  352.    }
  353.    function setToggle(val)
  354.    {
  355.       this.__toggle = val;
  356.       if(this.__toggle == false)
  357.       {
  358.          this.setState(false);
  359.       }
  360.    }
  361.    function getToggle(Void)
  362.    {
  363.       return this.__toggle;
  364.    }
  365.    function set toggle(val)
  366.    {
  367.       this.setToggle(val);
  368.    }
  369.    function get toggle()
  370.    {
  371.       return this.getToggle();
  372.    }
  373.    function set value(val)
  374.    {
  375.       this.setSelected(val);
  376.    }
  377.    function get value()
  378.    {
  379.       return this.getSelected();
  380.    }
  381.    function set selected(val)
  382.    {
  383.       this.setSelected(val);
  384.    }
  385.    function get selected()
  386.    {
  387.       return this.getSelected();
  388.    }
  389.    function setSelected(val)
  390.    {
  391.       if(this.__toggle)
  392.       {
  393.          this.setState(val);
  394.       }
  395.       else
  396.       {
  397.          this.setState(!this.initializing ? this.__state : val);
  398.       }
  399.    }
  400.    function getSelected()
  401.    {
  402.       return this.__state;
  403.    }
  404.    function setEnabled(val)
  405.    {
  406.       if(this.enabled != val)
  407.       {
  408.          super.setEnabled(val);
  409.          this.invalidate();
  410.       }
  411.    }
  412.    function onPress(Void)
  413.    {
  414.       this.pressFocus();
  415.       this.phase = "down";
  416.       this.refresh();
  417.       this.dispatchEvent({type:"buttonDown"});
  418.       if(this.autoRepeat)
  419.       {
  420.          this.interval = setInterval(this,"onPressDelay",this.getStyle("repeatDelay"));
  421.       }
  422.    }
  423.    function onPressDelay(Void)
  424.    {
  425.       this.dispatchEvent({type:"buttonDown"});
  426.       if(this.autoRepeat)
  427.       {
  428.          clearInterval(this.interval);
  429.          this.interval = setInterval(this,"onPressRepeat",this.getStyle("repeatInterval"));
  430.       }
  431.    }
  432.    function onPressRepeat(Void)
  433.    {
  434.       this.dispatchEvent({type:"buttonDown"});
  435.       updateAfterEvent();
  436.    }
  437.    function onRelease(Void)
  438.    {
  439.       this.releaseFocus();
  440.       this.phase = "rollover";
  441.       if(this.interval != undefined)
  442.       {
  443.          clearInterval(this.interval);
  444.          delete this.interval;
  445.       }
  446.       if(this.getToggle())
  447.       {
  448.          this.setState(!this.getState());
  449.       }
  450.       else
  451.       {
  452.          this.refresh();
  453.       }
  454.       this.dispatchEvent({type:"click"});
  455.    }
  456.    function onDragOut(Void)
  457.    {
  458.       this.phase = "up";
  459.       this.refresh();
  460.       this.dispatchEvent({type:"buttonDragOut"});
  461.    }
  462.    function onDragOver(Void)
  463.    {
  464.       if(this.phase != "up")
  465.       {
  466.          this.onPress();
  467.          return undefined;
  468.       }
  469.       this.phase = "down";
  470.       this.refresh();
  471.    }
  472.    function onReleaseOutside(Void)
  473.    {
  474.       this.releaseFocus();
  475.       this.phase = "up";
  476.       if(this.interval != undefined)
  477.       {
  478.          clearInterval(this.interval);
  479.          delete this.interval;
  480.       }
  481.    }
  482.    function onRollOver(Void)
  483.    {
  484.       this.phase = "rollover";
  485.       this.refresh();
  486.    }
  487.    function onRollOut(Void)
  488.    {
  489.       this.phase = "up";
  490.       this.refresh();
  491.    }
  492.    function getLabel(Void)
  493.    {
  494.       return this.fui.text;
  495.    }
  496.    function setLabel(val)
  497.    {
  498.       if(typeof this.fui == "string")
  499.       {
  500.          this.createLabel("fui",8,val);
  501.          this.fui.styleName = this;
  502.       }
  503.       else
  504.       {
  505.          this.fui.text = val;
  506.       }
  507.       var _loc4_ = this.fui._getTextFormat();
  508.       var _loc2_ = _loc4_.getTextExtent2(val);
  509.       this.fui._width = _loc2_.width + 5;
  510.       this.fui._height = _loc2_.height + 5;
  511.       this.iconName = this.fui;
  512.       this.setView(this.__state);
  513.    }
  514.    function get emphasized()
  515.    {
  516.       return this.__emphasized;
  517.    }
  518.    function set emphasized(val)
  519.    {
  520.       this.__emphasized = val;
  521.       var _loc2_ = 0;
  522.       while(_loc2_ < 8)
  523.       {
  524.          this[this.idNames[_loc2_]] = this.stateNames[_loc2_] + "Skin";
  525.          if(typeof this[this.idNames[_loc2_ + 8]] == "movieclip")
  526.          {
  527.             this[this.idNames[_loc2_ + 8]] = this.stateNames[_loc2_] + "Icon";
  528.          }
  529.          _loc2_ = _loc2_ + 1;
  530.       }
  531.       this.showEmphasized(this.__emphasized);
  532.       this.setStateVar(this.__state);
  533.       this.invalidateStyle();
  534.    }
  535.    function keyDown(e)
  536.    {
  537.       if(e.code == 32)
  538.       {
  539.          this.onPress();
  540.       }
  541.    }
  542.    function keyUp(e)
  543.    {
  544.       if(e.code == 32)
  545.       {
  546.          this.onRelease();
  547.       }
  548.    }
  549.    function onKillFocus(newFocus)
  550.    {
  551.       super.onKillFocus();
  552.       if(this.phase != "up")
  553.       {
  554.          this.phase = "up";
  555.          this.refresh();
  556.       }
  557.    }
  558. }
  559.